package com.yantong.controller.customer;

import com.yantong.annotation.Log;
import com.yantong.controller.BaseController;
import com.yantong.result.ResultVo;
import com.yantong.utils.PageUtils;
import com.yantong.pojo.ListMemberParams;
import com.yantong.pojo.Member;
import com.yantong.service.RegCommanderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
  * @Description:
  * Copyright: Copyright (c) 2018 
  * Company: 黑名单列表
  * @author xiangyi
  * @version V1.0.0
  * @since 3.0
  * @date 2018年9月4日 上午10:04:23
 */
@Controller
@RequestMapping("/blacklist/manage")
public class BlackCommanderController extends BaseController {

    private static final String prefix = "commander/manage";

    @Autowired
    private RegCommanderService regCommanderService;

    /**
     * 黑名单列表界面
     * @return
     */
    @GetMapping()
    @RequiresPermissions("blacklist:manage:manage")
    public String closeCommanders(Model model) {
        model.addAllAttributes(getCentreIdModelInfo());
        return prefix + "/blackCommanders";
    }


    /**
     * 黑名单列表 
     * @param listMemberParams
     * @param member
     * @param offset
     * @param limit
     * @return
     */
    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("blacklist:manage:manage")
    public PageUtils<Member> blackListCommander(ListMemberParams listMemberParams, Member member, int offset, int limit){
        if (listMemberParams.getCentreId() == null) {
            listMemberParams.setCentreId(getUserCentreId());
        }
        return regCommanderService.blackListCommander(listMemberParams, member, offset, limit);
    }
    
    /**
     * 移除黑名单
     * @param id
     * @return
     */
    @Log(module = "黑名单管理", operation = "移除黑名单")
    @RequiresPermissions("removeBlack:manage:manage")
    @ResponseBody
    @PostMapping("/removeBlack")
    public ResultVo removeBlack(Long id) {
        if (id == null) {
            return ResultVo.error();
        }
        if (regCommanderService.removeBlack(id) <1) {
            return ResultVo.error();
        }
        return ResultVo.ok();
    }
    
}
